/*
	DIMGA
	Distributed Island Model Genetic Algorithm 

	Copyright (c) 2006 Nikola Sivacki nsivacki@gmail.com

	This program is free software; you can redistribute it and/or
	modify in under the terms of the GNU General Public Licence as
	published by the Free Software Foundation; either version 2 of
	the Licence, or [at your option] any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAT PURPOSE. See the
	GNU General Public Licence for more details.

	You should have received a copy of the GNU General Public Licence
	along with this program; if not, write to the Free Software 
	Foundation Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef _LOG_H
#define _LOG_H

#define error(...) fprintf(stderr, __VA_ARGS__); fprintf(flog, "\n");
#define log(...)   fprintf(flog, __VA_ARGS__);   fprintf(flog, "\n");

static FILE *flog;

static void initlog(const char* file=NULL) 
{ 
  if (file!=NULL)
  { 
    flog = fopen(file, "wt");
    if (flog==NULL)
    {
      error("Cannot open log file %s\n", file);
      return;
    }
  } 
  else
  {
    flog=stdout;
  }
}


static void closelog()
{
  fclose(flog);
}

#ifdef _DEBUG
  #define debug(...) fprintf(flog, __VA_ARGS__); fprintf(flog,"\n");
#else
  #define debug(...) 
#endif

#endif
